package com.cat.twoPointerTechnique;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/description/
 * @create 2025/8/8 15:52
 * @since JDK17
 */

public class Solution24 {
    public boolean winnerOfGame(String colors) {
        int n = colors.length() - 1;
        char a, b, c;
        for (int i = 1, j = 1; i < n && j < n; ) {
            while (i < n) {
                a = colors.charAt(i - 1);
                b = colors.charAt(i);
                c = colors.charAt(i + 1);
                if (a == 'A' && b == 'A' && c == 'A') break;
                i++;
            }
            if (i == n) {
                return false;
            } else {
                i += 2;
            }
            while (j < n) {
                a = colors.charAt(j - 1);
                b = colors.charAt(j);
                c = colors.charAt(j + 1);
                if (a == 'B' && b == 'B' && c == 'B') break;
                j++;
            }
            if (j == n) {
                return true;
            } else {
                j += 2;
            }
        }
        return false;
    }
}
